/**
 * @name: 保留两位小数
 * @param {*}
 * @return {*}
 */
const keepTwo = value => {
  let newVal = parseFloat(value).toFixed(2);
  let last1 = newVal.substring(newVal.length - 1, newVal.length);
  let last2 = newVal.substring(newVal.length - 2, newVal.length - 1);
  if (last1 === 0 && last2 === 0) {
    newVal = parseFloat(value).toFixed(0);
  } else if (last1 === 0) {
    newVal = parseFloat(value).toFixed(1);
  }

  return newVal;
};

/**
 * @name: 累加
 * @param {Array}
 * @return {Array}
 */
const accuMulate = (...args) => {
  return args.reduce((i, s) => { return i + s }, 0)
}

/**
 * @name: 银行卡分隔
 * @param {*}
 * @return {String}
 */
const bank_filter = val =>{
  val += '';
  val = val.replace(/(\s)/g,'').replace(/(\d{4})/g,'$1 ').replace(/\s*$/,'');
  return val;
}

/**
 * @name: 对象处理为数组对象
 * @param {Object}
 * @return {Array}
 */
const objToArrObj = obj => {
  let arr = []
  for(let i in obj){
    arr.push({[i]:obj[i]})
  }
  return arr
}
export default {
  keepTwo,
  accuMulate,
  bank_filter,
  objToArrObj
};